package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TWfActivityInstanceVo;
import com.ruoyi.system.basicInformation.bo.TWfActivityInstanceQueryBo;
import com.ruoyi.system.basicInformation.bo.TWfActivityInstanceAddBo;
import com.ruoyi.system.basicInformation.bo.TWfActivityInstanceEditBo;
import com.ruoyi.system.basicInformation.service.ITWfActivityInstanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 案件流程Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "案件流程控制器", tags = {"案件流程管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/instance")
public class TWfActivityInstanceController extends BaseController {

    private final ITWfActivityInstanceService iTWfActivityInstanceService;

    /**
     * 查询案件流程列表
     */
    @ApiOperation("查询案件流程列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:list')")
    @GetMapping("/list")
    public TableDataInfo<TWfActivityInstanceVo> list(TWfActivityInstanceQueryBo bo) {
        startPage();
        List<TWfActivityInstanceVo> list = iTWfActivityInstanceService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出案件流程列表
     */
    @ApiOperation("导出案件流程列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:export')")
    @Log(title = "案件流程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TWfActivityInstanceVo> export(TWfActivityInstanceQueryBo bo) {
        List<TWfActivityInstanceVo> list = iTWfActivityInstanceService.queryList(bo);
        ExcelUtil<TWfActivityInstanceVo> util = new ExcelUtil<TWfActivityInstanceVo>(TWfActivityInstanceVo.class);
        return util.exportExcel(list, "案件流程");
    }

    /**
     * 获取案件流程详细信息
     */
    @ApiOperation("获取案件流程详细信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:query')")
    @GetMapping("/{id}")
    public AjaxResult<TWfActivityInstanceVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTWfActivityInstanceService.queryById(id));
    }

    /**
     * 新增案件流程
     */
    @ApiOperation("新增案件流程")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:add')")
    @Log(title = "案件流程", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TWfActivityInstanceAddBo bo) {
        return toAjax(iTWfActivityInstanceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改案件流程
     */
    @ApiOperation("修改案件流程")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:edit')")
    @Log(title = "案件流程", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TWfActivityInstanceEditBo bo) {
        return toAjax(iTWfActivityInstanceService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除案件流程
     */
    @ApiOperation("删除案件流程")
    @PreAuthorize("@ss.hasPermi('basicInformation:instance:remove')")
    @Log(title = "案件流程" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTWfActivityInstanceService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
